package com.supermali.entity.npc.bullet;

import com.supermali.behavior.move.land.BulletMove;
import com.supermali.creater.MapCreater;
import com.supermali.creater.img.ImgHelper;
import com.supermali.creater.img.ImgKey;
import com.supermali.creater.img.ImgLoader;
import com.supermali.entity.MapImageAbstract;
import com.supermali.entity.npc.IntesectDirect;
import com.supermali.entity.npc.monistor.hurt.HurtAbstract;

import java.awt.image.BufferedImage;
import java.util.List;
import java.util.Set;

public class Bullet extends BulletAbstract {

    private BulletMove bulletMove;

    public Bullet(Double x, Double y, MapCreater mapCreater) {
        super(x, y, mapCreater);
    }

    @Override
    public void proccessData(long delta) {
        Set<IntesectDirect> intesectDirects = super.checkCollide();
        for(IntesectDirect intesectDirect: intesectDirects){
            IntesectDirect.Direct direct = intesectDirect.getDirect();
            if(intesectDirect.getIntesect() instanceof HurtAbstract){
                List<MapImageAbstract> removes = getMapCreater().getRemoves();
                removes.add(intesectDirect.getIntesect());
                removes.add(this);
            }else {
                if (direct == IntesectDirect.Direct.TOP) {
                    bulletMove.setYdirect(1);
                } else if (direct == IntesectDirect.Direct.LEFT) {
                    MapCreater mapCreater = getMapCreater();
                    //mapCreater.getBulletAbstracts().remove(this);
                    mapCreater.getRemoves().add(this);
                }
            }
        }
        bulletMove.move(delta);
    }

    @Override
    public void init() {
        ImgHelper imgHelper = ImgLoader.getImgHelper(ImgKey.Bullet.CIRCLE);
        BufferedImage select = imgHelper.select(0);
        this.setBufferedImage(select);
        bulletMove = new BulletMove(this);
    }

    public void setXdirect(int direct){
        bulletMove.setXdirect(direct);
    }
}
